package com.it.material.mapper;

import com.it.material.entity.NewsEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {

    //用户发布文章
    @Insert("INSERT INTO `wm_news` (title, content, channel_id, user_id, status, created_time, updated_time, publish_time) VALUES (#{title}, #{content}, #{channelId}, #{userId}, #{status.code}, #{createTime}, #{updateTime}, #{publishTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") // 获取自增主键
    void insertNews(NewsEntity newsEntity);

    // 单个图片插入
    @Insert("INSERT INTO news_images (news_id, image_url) VALUES (#{newsId}, #{imageUrl})")
    void insertNewsImage(@Param("newsId") Long newsId, @Param("imageUrl") String imageUrl);



    //批量插入图片URL
    default void insertNewsImages(Long newsId, List<String> imageUrls) {
        if (imageUrls != null && !imageUrls.isEmpty()) {
            imageUrls.forEach(imageUrl -> insertNewsImage(newsId, imageUrl));
        }
    }



}